# 打包镜像
FROM golang:1.21 as builder

WORKDIR /opt/app
COPY . .
# 启用 Go Modules 功能
RUN go env -w GO111MODULE=on

# 配置 GOPROXY 环境变量
RUN go env -w  GOPROXY=https://goproxy.cn,direct

# 编译
RUN CGO_ENABLED=0 go build -o xiezhi

# 制作镜像
# 可调试镜像
# # 83.5MB
# FROM ubuntu:latest
# 16.3MB
# FROM alpine:latest
# 最小镜像，不可调整
# 10.7MB
FROM scratch

WORKDIR /code
COPY --from=builder /opt/app/xiezhi /code/xiezhi

ENV HTTP_PORT 9090
EXPOSE 9090

CMD ["/code/xiezhi"]